package tjs.styudy.mini.springboot.transaction;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tjs.styudy.mini.springboot.transaction.config.TransactionManager;
import tjs.styudy.mini.springboot.transaction.utils.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by Nicky.Tang on 2021/10/27 4:27 下午
 *
 * @since 02.12.10
 */
@Configuration
public class TransactionAutoConfiguration {

    @Bean
    public TransactionManager initTransactionManager(ObjectProvider<DataSource> dataSourceProvider) {
        TransactionManager transactionManager = new TransactionManager(dataSourceProvider);
        return transactionManager;
    }

    @Bean
    public JdbcTemplate initJdbcTemplate(ObjectProvider<DataSource> dataSource) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        return jdbcTemplate;
    }

}
